function personalInfo(func){
	if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
		function setupWebViewJavascriptBridge(callback) {
			if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
			if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
			window.WVJBCallbacks = [callback];
			var WVJBIframe = document.createElement('iframe');
			WVJBIframe.style.display = 'none';
			WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
			document.documentElement.appendChild(WVJBIframe);
			setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
		 };
		 setupWebViewJavascriptBridge(function(bridge) {
		   var uniqueId = 1
		   function log(message,data) {	  
			 func(data);
		   }
		   bridge.callHandler('personalInformation', null, function(response) {
		 	log("获取数据", response)
		   })                        
		 })                
	} else if (/(Android)/i.test(navigator.userAgent)) {
		let data = {};
		window.WebViewJavascriptBridge.callHandler('personalInformation',data,function(responseData){
			var responseData = JSON.parse(responseData);
			 func(responseData)
			 //that.$store.commit('setInfo',Object.assign(that.$store.state.myInfo,responseData));
		});
	} else {
		return;
	};
}

function walletHomeBack(){
	if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
		function setupWebViewJavascriptBridge(callback) {
			if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
			if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
			window.WVJBCallbacks = [callback];
			var WVJBIframe = document.createElement('iframe');
			WVJBIframe.style.display = 'none';
			WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
			document.documentElement.appendChild(WVJBIframe);
			setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
		 };
		 setupWebViewJavascriptBridge(function(bridge) {
		    bridge.callHandler('walletHomeBack', null, function(response) { })                        
		})
		bridge.callHandler('walletHomeBack', null, function(response) {});                        
	} else if (/(Android)/i.test(navigator.userAgent)) {
		window.location.href='window.androidcard.htmlback';
	} else {
		return;
	};
}
function nativeJump(obj,cb) {
	if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
		function setupWebViewJavascriptBridge(callback) {
			if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
			if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
			window.WVJBCallbacks = [callback];
			var WVJBIframe = document.createElement('iframe');
			WVJBIframe.style.display = 'none';
			WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
			document.documentElement.appendChild(WVJBIframe);
			setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
		 };
		 setupWebViewJavascriptBridge(function(bridge) {
			let data  = obj;
			function log(message,data) {
				typeof(cb)=== "function" && cb(data);
			}
			bridge.callHandler('nativeJump',data, function(response) {
				log("获取数据", response)
			});                        
		 })
	}else if(/(Android)/i.test(navigator.userAgent)){
		let data  = obj;
		window.WebViewJavascriptBridge.callHandler('nativeJump',data,function(responseData){
			var responseData = JSON.parse(responseData); 
			typeof(cb)=== "function" && cb(responseData);
		});
	}
}

var dateFormat = {
    padLeftZero: function (str) {
        return ('00' + str).substr(str.length)
    },
    formatDate: function (date, fmt) {
        if (/(y+)/.test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
        }
        let o = {
            'M+': date.getMonth() + 1,
            'd+': date.getDate(),
            'h+': date.getHours(),
            'm+': date.getMinutes(),
            's+': date.getSeconds()
        }
        for (let k in o) {
            if (new RegExp(`(${k})`).test(fmt)) {
                let str = o[k] + ''
                fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : this.padLeftZero(str))
            }
        }
        return fmt
    }
}

module.exports = {
	walletHomeBack:walletHomeBack,
    personalInfo:personalInfo,
    dateFormat:dateFormat,
	nativeJump:nativeJump
}
